package com.xauto.pioneer.appuser.model;

import android.content.Context;

import net.tsz.afinal.FinalDb;
import net.tsz.afinal.annotation.sqlite.Id;
import net.tsz.afinal.annotation.sqlite.Table;

import org.json.JSONObject;

/**
 * 配置版本
 * @author Lemon Thu 9 Feb 2017 15:44
 */
@Table(name = "config_version")
public class ConfigVersion  extends BaseModel<ConfigVersion>{

    @Id(column = "version_id")
    public int versionId;
    /** 地区版本*/
    public String region = "0";
    /** 银行版本*/
    public String bank = "0";
    /** 支付方式版本*/
    public String payment = "0";
    /** 计费规则版本*/
    public String billing_rules = "0";
    /** 开始时间*/
    public String start_date = "";
    /** 结束时间*/
    public String end_date = "";

    public int getVersionId() {
        return versionId;
    }

    public void setVersionId(int versionId) {
        this.versionId = versionId;
    }

    public String getRegion() {
        return region;
    }

    public void setRegion(String region) {
        this.region = region;
    }

    public String getBank() {
        return bank;
    }

    public void setBank(String bank) {
        this.bank = bank;
    }

    public String getPayment() {
        return payment;
    }

    public void setPayment(String payment) {
        this.payment = payment;
    }

    public String getBilling_rules() {
        return billing_rules;
    }

    public void setBilling_rules(String billing_rules) {
        this.billing_rules = billing_rules;
    }

    public String getStart_date() {
        return start_date;
    }

    public void setStart_date(String start_date) {
        this.start_date = start_date;
    }

    public String getEnd_date() {
        return end_date;
    }

    public void setEnd_date(String end_date) {
        this.end_date = end_date;
    }

    public ConfigVersion() {
        this.versionId = 0;
    }

    public void saveDb(Context mContext, ConfigVersion configVersion) {
        FinalDb finalDb = FinalDb.create(mContext);
        finalDb.deleteByWhere(ConfigVersion.class, "");
        finalDb.save(configVersion);
    }

    @Override
    public ConfigVersion parse(JSONObject jsonObject) {
        if (jsonObject != null) {
            this.region = jsonObject.optString("region");
            this.bank = jsonObject.optString("bank");
            this.payment = jsonObject.optString("payment");
            this.billing_rules = jsonObject.optString("billing_rules");
            this.start_date = jsonObject.optString("start_date");
            this.end_date = jsonObject.optString("end_date");
            return this;
        }
        return null;
    }
}
